<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <div :class="eleTabTop <= 85 ? 'eleTab' : ''" class="informationTab" ref="eleTab">
      <el-table v-loading="loading" :data="TimeList">
        <el-table-column label="序号" align="center" type="index" width="100" />
        <el-table-column label="提醒时间（分钟）" align="center" prop="pvalues" min-width="200" :show-overflow-tooltip="true" />
        <el-table-column label="编辑时间" align="center" prop="updateTime" min-width="200" :show-overflow-tooltip="true" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="200">
          <template slot-scope="scope">
            <el-button v-hasPermi="['tTimeparameter:timeparameter:edit']" size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">修改</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>
    <!-- 添加或修改信息对话框 -->
    <el-dialog title="设置提醒时间" :visible.sync="open" width="650px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="提醒时间" prop="pvalues">
          <el-input placeholder="请输入提醒时间" v-model="form.pvalues" @input="form.pvalues=form.pvalues.replace(/^0|[^0-9]/g,'')">
            <template slot="append">分钟</template>
          </el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {
    timeparameter,
    updatetimeparameter
  } from "@/api/urgencyRemovework";

  export default {
    name: "Car",
    data() {
      return {
        eleTabTop: 0, //表格容器eleTabTop距浏览器顶部距离
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        TimeList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          pvalues: [{
            required: true,
            message: "提醒时间不能为空",
            trigger: "blur"
          }],
        },
      };
    },
    created() {
      this.getList();
    },
    mounted() {
      // 滚动条的获取
      this.handleScrollx();
      window.addEventListener("scroll", this.handleScrollx, true);
    },
    activated() {
      //获取表格容器距页面头部的距离
      this.handleScrollx();
    },
    destroyed() {
      window.removeEventListener("scroll", this.handleScrollx, true);
    },
    methods: {
      //获取表格容器距页面头部的距离
      handleScrollx() {
        this.eleTabTop = this.$refs.eleTab.getBoundingClientRect().top;
      },
      /** 查询车辆信息列表 */
      getList() {
        this.loading = true;
        timeparameter(this.queryParams).then((response) => {
          this.TimeList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
      },
      // 表单重置
      reset() {
        this.form = {
          pvalues: null,
          id: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        this.form.id = row.id;
        this.form.pvalues = row.pvalues;
        this.open = true;
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate((valid) => {
          if (valid) {
            updatetimeparameter(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          }
        });
      }
    },
  };
</script>
